home *** CD-ROM | disk | FTP | other *** search
-
-
-
- L I S T L I S T 5.0 U S E R ' S G U I D E
- =================================================
-
- SUMMARY:......................................................................
-
- ListList is an easy-to-use linked list manager. It solves the general
- problem of how to organize odd pieces of data held anywhere in memory.
- Comes complete with a user's guide, source code for a library of over 100
- carefully explained procedures and a comprehensive test program.
- Features a fast method for sorting long lists. Written in portable ANSI 'C'.
- Distributed on a try-before-you-buy basis; price $5.
-
-
- INTRODUCTION:.................................................................
-
- All computer programs manipulate data. The form in which data is held has an
- impact on the procedures that use that data. If the data is well organized
- and easily accessible then the procedures can be written in a clear and
- easily understood way. In other words, clean data structures permit clean
- procedures.
-
- Data can be of irregular size and there may be lots of it. In general, how
- does one grasp and deal with many different things? A natural way to organize
- many things is to make a list.
-
- Lists inside a computer can be represented as a flexible data structure called
- a linked list. A linked list can make processing data easier by ordering and
- grouping related data.
-
- A SIMPLE EXAMPLE USING LISTLIST:..............................................
-
- As a demonstration let's make a list of names, sort the list and then search
- for a particular name in the list. The details will be explained later.
-
-
- Here's a picture of the list we will make:
-
-
- 'AList' ----> [LIST]
- |
- [ITEM]--->[Dagny Taggart]
- |
- [ITEM]--->[Francisco d'Anconia]
- |
- [ITEM]--->[Hank Reardon]
- |
- [ITEM]--->[Hugh Akston]
- |
- [ITEM]--->[John Galt]
-
- Building the list:
-
-
- AddressOfList AList; /* This variable holds the */
- /* address of the list record. */
-
- /* These are the data records to be itemized. */
- Byte John[] = "John Galt";
- Byte Dagny[] = "Dagny Taggart";
- Byte Hank[] = "Hank Reardon";
- Byte Frisco[] = "Francisco d'Anconia";
- Byte Hugh[] = "Hugh Akston";
-
- AList = CreateList(); /* Allocate a new list record */
-
- InsertDataLastInList( AList, Dagny );
- InsertDataLastInList( AList, Frisco );
- InsertDataLastInList( AList, Hank );
- InsertDataLastInList( AList, Hugh );
- InsertDataLastInList( AList, John );
-
- Sorting the list:
-
- SortListAlphabetically( AList );
-
- Searching the list:
-
- SearchKey = (AddressOfByte) "John";
- KeyFieldOffset = 0;
- KeyFieldWidth = 4;
-
- MatchingItem = FindFirstMatchingItem( AList,
- KeyFieldOffset,
- KeyFieldWidth,
- SearchKey );
-
-
- End of Example.
-
- WHAT ELSE CAN BE DONE WITH LISTLIST:..........................................
-
- Usage is not limited to lists of strings: any kind of data located anywhere in
- addressable memory can be itemized and manipulated via lists. ListList can be
- used to make structures like stacks, queues, symbol tables, hierarchies and
- databases.
-
- A list can be used as a stack:
-
- [ ] <--> [ ]=[ ]=[ ]=[ ]
-
- A list can be used as a queue:
-
- [ ] <-- [ ]=[ ]=[ ] <-- [ ]
-
- A list can refer to other lists:
-
- [ ]->[ ]=[ ]=[ ]
- |
- [ ]->[ ]
- |
- [ ]->[ ]=[ ]
-
- LEARNING TO USE LISTLIST:.....................................................
-
- Read through the Theory of Operation section below then see the source code
- and test program for examples.
-
- Every procedure in the source code is preceded by a comment block. The
- comment block headings are self explanitory except for 'ASSUMES'. These are
- the assumptions that must be true in order for the procedure to work properly.
- If a condition is listed under the 'ASSUMES' heading then no test is made
- within the procedure to determine if the condition exists: it is assumed to
- hold.
-
- The source code itself is written in a descriptive way. I strive to write
- code that MUST work, not just code that happens to work. To do this it has
- to be written simply and clearly so that it can be validated conceptually
- prior to running it. And then I test it.
-
- I rank clarity over brevity of code. My theory of software writing and
- validation is best expressed by this quote from Oliver Heaviside, the self-
- taught 19th Century physicist:
-
- "The best of all proofs is to set out the fact
- descriptively so that it can be seen to be a fact."
-
-
- THEORY OF OPERATION:..........................................................
-
- This section is broken into five parts:
-
- 1. The Item Record: Building Block Of Linked Lists
- 2. The List Record: Place Holder For A List
- 3. Operations: How To Operate On A Linked List
- 4. The List Stack: A Convenient Place To Preserve List Addresses
- 5. SetUp & CleanUp: What To Do First & Last
-
- THE ITEM RECORD: BUILDING BLOCK OF LINKED LISTS...............................
-
- The basic idea behind the linked list is that each element of data is
- represented by a uniform data record called an item.
-
- Items can be connected together into chains so that related data can be
- grouped together and accessed in a desired order.
-
- Item records provide a basic ordering and directory function. From an item
- record it is possible to find the location of the data associated with that
- item, and the locations of the items before and after the item.
-
- Each item record consists of four elements:
-
- 1. The address of the data that the item stands for.
- 2. The address of the prior item in the list.
- 3. The address of the next item in the list.
- 4. A mark used to select or distinguish an item from other items in the
- same list.
-
- [ITEM] (2)
- ^
- | Item Record
- | --------------------------
- ----| AddressOfPriorItem |
- |------------------------|
- ----| AddressOfNextItem |
- | |------------------------| (1)
- | | AddressOfData |--->[ DATA....//.... ]
- | |------------------------|
- | | ItemMark |
- | --------------------------
- | (4)
- [ITEM] (3)
-
-
- The 'ItemMark' field of an item record is used to signify that an item is
- special in some way. Some situations call for the selection of some items of
- data from a wider group based on a selection criteria. For example, in a list
- of names it may be desirable to delete all data records containing the last
- name 'Smith'. A procedure might be written to scan through the list and mark
- all items that refer to data containing the name 'Smith'. Then the routine
- 'DeleteMarkedItems()' could be called to complete the job.
-
- THE LIST RECORD: PLACE HOLDER FOR A LIST......................................
-
- Items of a list can be inserted, extracted and reordered. But what happens
- when the last item of a list is extracted? Does the list go away?
-
- The need for a fixed way of referring to a list, apart from the items it
- contains, gives rise to the need for a second kind of record, the List Record:
-
- List Record
- --------------------------
- | AddressOfFirstItem |--->[ITEM]--[ITEM]--[ITEM]
- |------------------------| ^
- | AddressOfLastItem |-----------------------|
- |------------------------|
- | ItemCount |
- |------------------------|
- | ListMark |
- --------------------------
-
- A list record is a place holder for the list and contains information about
- the list: how many items there are, where the first and last item records can
- be found and a 'ListMark' field similar in function to the 'ItemMark' field
- in the item record.
-
- The 'AddressOfLastItem' field is included solely for speed: when items are
- appended to the end of a list, the last item can be located directly without
- having to travel through the entire list. Also, the performance of operations
- that scan a list in reverse order is improved by the ability to go directly to
- the last item.
-
- The 'ItemCount' field holds a count of the items in the list and is kept
- current by all of the procedures that insert or extract items. The
- 'ItemCount' field saves time by eliminating the need to count the items in
- a list.
-
- The 'ListMark' field is used to signal that the list as a whole is special in
- some way. Lists can be marked and later that mark can be used to control
- processing of the list in the same way the 'ItemMark' field allows delayed
- processing of marked items.
-
- OPERATIONS: HOW TO OPERATE ON A LINKED LIST...................................
-
- ListList contains two major classes of operations:
-
- 1. General list functions which operate on any given list.
-
- 2. Special list functions which operate only on the current list.
-
- A general list function is any procedure that requires the address of a
- list as a parameter. For example,
-
- DeleteList(AddressOfList);
- DuplicateList(AddressOfList);
- ExtractItemFromList(AddressOfList,AddressOfItem);
-
- A special list function is a procedure that operates on the list currently
- referenced by the global variable 'TheList'. Here are some examples of this
- kind of list operation:
-
- ToFirstItem();
- ToLastItem();
- ToNextItem();
- ToPriorItem();
-
- Special list functions are convenient to use in situations where many
- operations are to be performed on the same list. Just store the list record
- address of your list into the variable called 'TheList' and then use the
- special list functions.
-
- Special list functions use two global variables:
-
- 1. 'TheList' holds the address of the current list record.
-
- 2. 'TheItem' holds the address of the current item record.
-
- For example, suppose you make a list of 3 strings like this:
-
- AddressOfList abcList;
- Byte aString[] = "a";
- Byte bString[] = "b";
- Byte cString[] = "c";
-
- abcList = CreateList();
-
- InsertDataLastInList(abcList, aString);
- InsertDataLastInList(abcList, bString);
- InsertDataLastInList(abcList, cString);
-
- 'abcList'
- |
- [LIST]
- |
- [ITEM]-->[a]
- |
- [ITEM]-->[b]
- |
- [ITEM]-->[c]
-
- Now suppose you want to capitalize each string in your list, this is how to
- do it using special list functions:
-
- 1. To make the list the current list, store the address of the list record
- into the global variable 'TheList':
-
- TheList = abcList;
-
- 2. Call 'ToFirstItem()' to make the first item the current item:
-
- ToFirstItem();
-
- 'abcList'
- |
- 'TheList'-->[LIST]
- |
- 'TheItem'-->[ITEM]-->[a]
- |
- [ITEM]-->[b]
- |
- [ITEM]-->[c]
-
- 3. This code operates on the current item and moves to the next one until
- there are no more items:
-
- /* Operate as long as 'TheItem' is non-zero. */
-
- while( TheItem )
- {
- /* 'TheDataAddress' refers to the data address of 'TheItem'. */
- ConvertStringToUpperCase( (AddressOfString) TheDataAddress );
-
-
- /* Move current item to the NEXT item in the list. */
- ToNextItem();
- }
-
- Alternatively, you can get the same result by processing the list in reverse
- order like this:
-
- TheList = abcList;
-
- ToLastItem(); /* Sets current item to be the last item in the list. */
-
- while(TheItem)
- {
- ConvertStringToUpperCase( (AddressOfString) TheDataAddress );
-
- /* Move current item to the PRIOR item in the list. */
- ToPriorItem();
- }
-
- For more examples see the general list functions in file 'ListList.c' which
- are written in terms of the special list functions.
-
- Here's a list of the most commonly used variables, macros and procedures
- associated with the special list:
-
- VARIABLES
-
- TheList............Holds the list record address of the current list.
-
- TheItem............Holds the item record address of the current item.
-
-
- MACROS: Use the following as if they were global variables:
-
- TheFirstItem.......Refers to the first item field of the current list.
-
- TheItemCount.......Refers to the item count field of the current list.
-
- TheLastItem........Refers to the last item field of the current list.
-
- TheListMark........Refers to the list mark field of the current list.
-
-
- TheDataAddress.....Refers to the data address field of current item.
-
- TheItemMark........Refers to the item mark field of the current item.
-
- TheNextItem........Refers to the next item field of the current item.
-
- ThePriorItem.......Refers to the prior item field of the current item.
-
-
- PROCEDURES
-
- PullTheListAndItem()....Pulls the values of the current list and item
- from the list stack.
-
- PushTheListAndItem()....Push the values of the current list and item
- onto the list stack.
-
- ToFirstItem()...........Sets the current item to be the first item
- in the current list.
-
- ToLastItem()............Sets the current item to be the last item
- in the current list.
-
- ToNextItem()............Sets the current item to be the item following
- the current item.
-
- ToPriorItem()...........Sets the current item to be the item preceding
- the current item.
-
- See the file 'ListList.h' for a complete list of all procedures and macros
- in the ListList library.
-
-
- THE LIST STACK: A CONVENIENT PLACE TO PRESERVE LIST ADDRESSES.................
-
- The above special list example assumes that there are no other pending
- procedures which depend on the values held in 'TheList' and 'TheItem'.
- To use 'TheList' and 'TheItem' without interfering with other procedures
- which may also use these variables, you need to preserve and restore their
- values.
-
- One way to do this is to save them on a special stack designed exclusively
- for this purpose. Here's a procedure that shows how:
-
- Nothing
- CapitalizeList(AddressOfList AList)
- {
- PushTheListAndItem(); /* Push the current list and item onto the list
- * stack.
- */
- TheList = AList;
- ToFirstItem();
-
- while(TheItem)
- {
- ConvertStringToUpperCase( (AddressOfString) TheDataAddress );
-
- ToNextItem();
- }
-
- PullTheListAndItem(); /* Pull the current list and item from the
- * list stack.
- */
- }
-
- Use 'PushTheListAndItem()' before any special list operations to preserve the
- current values of 'TheList' and 'TheItem' on the list stack.
-
- After you have finished using the special list functions, restore the values
- preserved on the list stack using 'PullTheListAndItem()'.
-
- SET UP & CLEAN UP: WHAT TO DO FIRST & LAST....................................
-
- Before ListList functions can be used the system must be set up for use. Call
- the following procedure to pre-allocate memory for use as list and item
- records.
-
- SetUpTheListSystem( MaxCountOfLists, MaxCountOfItems );
-
- The parameters you give to this procedure set an upper limit on how many
- lists or items can be used at one time.
-
- Use the following procedure to deallocate list and item memory:
-
- CleanUpTheListSytem();
-
- GETTING STARTED: RUNNING THE TEST PROGRAM.....................................
-
- ListList has been fully tested and is free of errors, but you should compile
- and run the test program, 'ListTest.c', to make sure that it works properly
- with your compiler. Some revision to the data types in file 'DataSize.h' may
- be required for your system.
-
- PACKING LIST:.................................................................
-
- There are 9 files in the ListList product:
-
- 1. ListList.DOC..ListList 5.0 User's Guide (this file)
- 2. Bytes.c.......Byte manipulation procedures
- 3. Bytes.h.......Byte library interface file
- 4. DataSize.h....Compiler-specific definitions
- 5. ListList.c....List manipulation procedures
- 6. ListList.h....List library interface file
- 7. ListTest.c....Test and example program
- 8. Strings.c.....String manipulation procedures
- 9. Strings.h.....String library interface file
-
- Shipped in compressed form as 'ListList.ZIP'.
-
- FURTHER READING ON LINKED LISTS:..............................................
-
- "Algorithms" by Robert Sedgewick, 2nd Ed. p.17
-
- "The Art Of Computer Programming, Vol. 1 Fundamental Algorithms" by
- Donald E. Knuth, 2nd Ed. p. 278
-
- USAGE TERMS:..................................................................
-
- This is commercial, for-profit software. As the author, my terms are strict
- but easy to meet: you may use my software if you pay me $5 cash.
-
- If you need a list manager then this is a good deal for both of us: you gain
- by saving several weeks of your most precious resource and I gain by earning
- my living.
-
- Use of ListList in software for profit or pleasure is encouraged. You may
- resell ListList as part of your product without any limitations. Feel free
- to edit the source to fit your style and add functions of your own.
-
- However, there is one usage restriction: use by government or non-profit
- organizations is prohibited.
-
- If you want to use ListList, the price is $5 cash with payment due when you
- have used it to save more than $5 worth of your time.
-
- Please mail cash payment to my permanent address:
-
- LEE MALONE
- 1800 MARKET ST. #221
- SAN FRANCISCO, CA 94102
-
- If you have more time than money, you can pay me in another way, by helping
- to distribute my product. Upload an unaltered copy of 'ListList.ZIP' to a
- new BBS or software library and you will have paid me in full.
-
- I value your business. Comments welcome.
-
- Sincerely,
-
- Lee Malone
-
-
- WARRANTY: I take pride in the quality of my work and stand by it. I warrant
- this product to be free of errors and will gladly send a full refund and a
- correction if you find an error that I missed.
-
- ==============================================================================